# Build recipe for feh.
#
# Copyright (c) 2018 Markus Tornow, <tornow@riseup.net>.
# Copyright (c) 2018-2019, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=feh
version=3.8
release=1

# Define a category for the output of the package name
pkgcategory=x-apps

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://feh.finalrewind.org/"$tarname"

description="
A fast and light image viewer.

Feh is a fast, lightweight image viewer which uses imlib2.  It is
command line-driven and supports multiple images through slideshows,
thumbnail browsing or multiple windows, and montages or index prints 
(using TrueType fonts to display file info).  Advanced features include
fast dynamic zooming, progressive loading, loading via HTTP (with
reload support for watching webcams), recursive file opening (slideshow
of a directory hierarchy), and mouse wheel/keyboard control. 
"

homepage=https://feh.finalrewind.org
license="MIT Expat variant"

# Source documentation
docs="AUTHORS COPYING ChangeLog README.md TODO"
docsdir="${docdir}/${program}-${version}"

# Limit parallel jobs for this build
jobs=1

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Replace default C flags with the ones provided by Qi
    sed -i "s/-g -O2/$QICFLAGS/" config.mk

    make -j${jobs} V=1 PREFIX=/usr
    make -j${jobs} V=1 \
     PREFIX=/usr \
     doc_dir="$destdir/$docsdir" \
     example_dir="$destdir/${docsdir}/examples" \
     DESTDIR="$destdir" install

    strip --strip-unneeded "${destdir}/usr/bin/feh"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

